package com.nf.practice.featureps;

import java.util.*;

/**
 * @author  Mr. Dong
 * @create  2021/11/24 11:18
 * @desc    补全月份并赋值为0
 **/
public class SupplementDateUtil {

    public static final String[] monthAndDay = new String[]{"01","02","03","04","05","06","07","08","09","10","11","12"};

    public static List<DataTrans> supplementDate(List<DataTrans> params){

        List<DataTrans> list = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        //当前年份
        int year = calendar.get(Calendar.YEAR);
        for (DataTrans data:params){
            list.add(data);
            for (String s:monthAndDay){
                DataTrans dataTrans = new DataTrans();
                String date = year+"-"+s;
                if (!date.equals(data.getName())){
                    dataTrans.setName(date);
                    dataTrans.setValue(0);
                    list.add(dataTrans);
                }
            }
        }
        // 集合中相同属性去重、值合并
        return RemovalData.merge(list);
    }



    public static void main(String[] args) {

        DataTrans dataTrans = new DataTrans("2021-08",0.05);
        DataTrans dataTrans1 = new DataTrans("2021-05",0.8);
        DataTrans dataTrans2 = new DataTrans("2021-05",0.8);
        DataTrans dataTrans3 = new DataTrans("2021-11",0.86);
        List<DataTrans> list = new ArrayList<>();
        list.add(dataTrans);
        list.add(dataTrans1);
        list.add(dataTrans2);
        list.add(dataTrans3);
        List<DataTrans> list1 = supplementDate(list);
        //根据月份升序排序
        Collections.sort(list1, Comparator.comparing(DataTrans::getName,(t1, t2) -> t1.compareTo(t2)));
        System.out.println(list1);
    }
}

